package com.letv.whatslive.model.convert;

import com.letv.whatslive.model.DeviceAllows;
import com.letv.whatslive.model.utils.ObjUtils;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import org.apache.commons.lang3.StringUtils;

//2015.11.4

/**
 * Created by shenyue on 2015/11/4.
 */
public class DeviceAllowsConvert {
    public static DBObject castDeviceAllowsToDBObject(DeviceAllows deviceAllows) {
        DBObject dbo = new BasicDBObject();
        if (deviceAllows.getId() != null) {
            dbo.put("_id", deviceAllows.getId());
        }

        if (StringUtils.isNotBlank(deviceAllows.getModel())) {
            dbo.put("model", deviceAllows.getModel());
        } else {
            dbo.put("model", "");
        }

        if (StringUtils.isNotBlank(deviceAllows.getSysVer())) {
            dbo.put("sysVer", deviceAllows.getSysVer());
        } else {
            dbo.put("sysVer", "");
        }

        return dbo;


//        DBObject dbo = new BasicDBObject();
//        if (device.getId() != null) {
//            dbo.put("_id", device.getId());
//        }
//        dbo.put("platformId",device.getPlatformId());
//        dbo.put("sysVer", device.getSysVer());
//        dbo.put("model", device.getModel());
//        dbo.put("appVer", device.getAppVer());
//        dbo.put("corporationId", device.getCorporationId());
//        dbo.put("channelId", device.getChannelId());
//        return dbo;
    }

    public static DeviceAllows castDBObjectToDeviceAllows(DBObject dbObject) {
        DeviceAllows deviceAllows = new DeviceAllows();
        if (dbObject != null) {
            deviceAllows.setId(ObjUtils.toLong(dbObject.get("_id")));
            deviceAllows.setSysVer(ObjUtils.toString(dbObject.get("sysVer")));
            deviceAllows.setModel(ObjUtils.toString(dbObject.get("model")));
        }

        return deviceAllows;
    }
}
